﻿/**
 * ...
 * @author 
 */

package list;


import client.INews;
import client.Item;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import gui.hug.LinkButton;
import loader.Loader;



class FavoriteItemPanel extends ItemPanel
{
	
	private var deleteButton : MyLinkButton;
	private static inline var Left : Float = 56;

	public function new(panelWidth : UInt, item : INews, index : UInt) 
	{
		deleteButton = new MyLinkButton();
		deleteButton.setNewText("Убрать из избранного");
		deleteButton.addEventListener(MouseEvent.CLICK, onDeleteFromFavorites);
		
		super (panelWidth, item, index,1);
		deleteButton.setLocation(Left + link.width + open.width +  20, 	fullNameHeight +
		fullDescriptionHeight + date.getBounds(date).height + 26 );
		hideButton.visible = false;
		addChild(deleteButton);		
	}
	/*
	private function deleteFromFavorites() {
		deleteButton = new MyLinkButton();
		deleteButton.setNewText("Убрать из избранного");
		deleteButton.addEventListener(MouseEvent.CLICK, onDeleteFromFavorites);
		deleteButton.setLocation(Left + link.width + open.width +  20, 	fullNameHeight +
			fullDescriptionHeight + date.getBounds(date).height + 26 );
		
		hideButton.visible = false;
		addChild(deleteButton);
	}
	*/
	private override function initOpen(type:Int) {
		open = new MyLinkButton();	
		open.setNewText("Открыть");
		open.addEventListener( MouseEvent.CLICK, openTab );
		open.setLocation(Left + link.width + 10,	fullNameHeight + fullDescriptionHeight + date.getBounds(date).height + 26);
		open.visible = !Std.is(content, Item);
		addChild(open);
	}
	
	
	private override function setVisibleElements() {
		if (stateChanged) {
			var visibility = mode == list.DisplayMode.selected;
			date.visible = visibility;
			open.visible = visibility;
			link.visible = visibility;
			deleteButton.visible = visibility;
			hideButton.visible = visibility;
			fullDescription.visible = visibility;
			shortDescription.visible = !visibility;
			fullName.visible = visibility;
			shortName.visible = !visibility;
		}
		hideButton.visible = false;
	}
	
	private function onDeleteFromFavorites(e : Dynamic) {
		var l : Loader = Loader.getInstance();
		l.deleteElementFromFavorites(cast(getContent().getChanId()));
		hide();
		cast(parent, NewList).draw();
	}
}